<?php
/**
 * admin service file Created by PhpStorm.
 * User: yang
 * Date: 2020/04/30
 */

namespace App\Http\Service\Admin;

use Common\Repository\PowerRepository;

class IndexService
{
    /**
     * 获取菜单列表
     * @param $admin_id
     * @return array
     */
    public function getMenuList($admin_id)
    {
        try {
            $result = PowerRepository::extendGetAll($admin_id);
            return makeTree($result);
        } catch (\Exception $exception) {
            return hello_error('失败！', $exception->getMessage());
        }
    }

    /**
     * 统计
     * @return array
     */
    public function statistics()
    {
        try {
            //头部统计
            $result['number'] = \Common\Repository\VisitsRepository::extendCount();
            $result['forum'] = \Common\Repository\ForumRepository::extendCount();
            $result['user'] = \Common\Repository\UserRepository::extendCount();

            //本月活跃用户
            $result['activeUsers'] = \Common\Repository\UserRepository::extendActiveUsers();

            return hello_success('ok', $result);
        } catch (\Exception $exception) {
            return hello_error('失败！', $exception->getMessage());
        }
    }

}